Node.js for PHP Developers by Daniel Howard
Author:Daniel Howard [Daniel Howard]
Language: eng
Format: epub, pdf
Tags: COMPUTERS / Web / Web Programming
ISBN: 9781449333799
Publisher: O'Reilly Media
Published: 2012-11-28T16:00:00+00:00
Other Variable Types
Objects, that is, PHP’s class-based system, can be converted to Node.js’s prototype-based system. The next chapter is devoted to converting both PHP classes to Node.js object with prototypes and PHP’s use of objects into the equivalent Node.js code that will use the corresponding Node.js objects.
PHP also has a two rather obscure variable types: resources and unknown types.
A PHP resource variable is an opaque data structure, also called a handle, whose data is only accessible by PHP API functions. For example, the PHP fopen() API function returns a resource value that points to a particular file. That resource value is stored in a variable and passed to other PHP API functions, such as fread(), fwrite(), and fclose(), which know how to understand the resource variables to read, write, and close the file, respectively. With resource variables, converting the variable itself from PHP to Node.js is not important; it is only important that the effect, such as reading, writing, or closing the file, takes place. Node.js has its own APIs for reading, writing, and closing files, so those are used instead. Converting file access from PHP to Node.js is specifically handled in Chapter 9.
Besides file access, other PHP resource variables are created when compressing or decompressing files, using cURL, reading or writing to databases, reading or writing from FTP servers, creating images and documents in specific formats, reading or writing LDAP servers, and receiving or sending email. In all these cases, the resource variable itself can be ignored and the PHP API function calls replaced with the corresponding Node.js API function calls.
An “unknown type” PHP variable is very obscure and may be a PHP resource variable that has been closed and rendered unusable. A PHP “unknown type” variable does not need to be converted to Node.js.
Node.js also has two variable types that have no corresponding types in PHP: function and undefined.
A Node.js function variable is a callback variable. The following Node.js code demonstrates that the f variable is a variable of type “function”:
var f = function() { }; console.log('The variable, f, is of type, "'+(typeof f)+'".');
The output of the Node.js code shows that the f variable is of a unique function type.
As you may recall from Chapter 4, PHP 5.3 introduced callback variables to the PHP language. Here’s a PHP 5.3 example of the previous Node.js code:
$f = function() { }; print 'The variable, $f, is of type, "'.(gettype($f)).'".';
The output of the PHP 5.3 example shows that PHP does not have a unique variable type for callback functions.
The variable $f is of type“object.”
PHP 5.3 callback functions are considered objects, along with other object variables that are not callback function variables. Node.js makes a distinction between functions and objects but PHP 5.3 does not.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
ActiveX | ASP.NET |
Cold Fusion | CSS |
DHTML | Java Server Pages |
JavaScript | PHP |
Python | Ruby |
XSL |
Hello! Python by Anthony Briggs(9867)
The Mikado Method by Ola Ellnestam Daniel Brolund(9747)
Dependency Injection in .NET by Mark Seemann(9293)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7745)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7517)
Svelte with Test-Driven Development by Daniel Irvine(6846)
Test-Driven Development with PHP 8 by Rainier Sarabia(6563)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(6512)
Layered Design for Ruby on Rails Applications by Dementyev Vladimir;(6431)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6378)
Web Development with Django by Ben Shaw Saurabh Badhwar(5882)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(5783)
React Application Architecture for Production by Alan Alickovic(5624)
Kotlin in Action by Dmitry Jemerov(5019)
Audition by Ryu Murakami(4555)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4297)
Software Architecture for Web Developers by Mihaela Roxana Ghidersa(4284)
Accelerating Server-Side Development with Fastify by Manuel Spigolon Maksim Sinik & Matteo Collina(4134)
Functional Programming in JavaScript by Mantyla Dan(4018)
